package com.study.modules.saas.controller;

import com.study.Util.CommonResponse;
import com.study.log.annotation.Log;
import com.study.modules.saas.service.RoleService;
import com.study.vo.RoleRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(value = "saas 角色")
@RestController
@RequestMapping("/sa/roles")
public class SaasRoleController {

    @Autowired
    RoleService roleService;

    @Log("角色创建")
    @ApiOperation("创建角色")
    @PostMapping()
    @PreAuthorize("@sa.hasPermission('role:add')")
    public CommonResponse create(@RequestBody @Validated RoleRequest request) {
        roleService.createRole(request);
        return CommonResponse.success();
    }

    @Log("删除角色")
    @ApiOperation("删除角色")
    @DeleteMapping("/{id}")
    @PreAuthorize("@sa.hasPermission('role:delete')")
    public CommonResponse delete(Integer id) {
        roleService.deleteRole(id);
        return CommonResponse.success();
    }




}
